{******************************Version: MPL 1.1*********************************
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Initial Developer : Fajar Khairil
*
* Portions created by the Initial Developer are Copyright (C) 2010 - 2011
* the Initial Developer. All Rights Reserved.
*
********************************************************************************
* This File is Part of HdFramework OPF Library
* Copyright (C) 2010 - 2011 HdFramework Developer Team
*
* Unit : HadeBaseConnection
* Description : Interface and base class for HadeConnection Concreate Connection
* Author: - Fajar Khairil
*		  - 
*******************************************************************************}

unit hadebaseconnection;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  hadebaseobject;

type

  { IHadeConnection }
  { Interface of HadeConnection }
  IHadeConnection = interface
    ['{0805073C-005B-48EE-918C-830EE12F6F3B}']

    { Transaction Method }
    procedure StartTransaction;
    procedure Commit;
    procedure Rollback;

    procedure Connect;
    procedure Disconnect;
    function isConnected: boolean;

    { Database Config Method }
    function getDatabase: string;
    function getHost: string;
    function getPassword: string;
    function getUsername: string;
    procedure setDatabase(AValue: string);
    procedure setHost(AValue: string);
    procedure setPassword(AValue: string);
    procedure setUsername(AValue: string);

    { describe itself }
    procedure ExecuteDirect(const ASql: string);

    procedure setDataSet(const ADataSet: Pointer);
    function getParams: TStrings;
    procedure setParams(AValue: TStrings);

    property Params : TStrings read getParams write setParams;
    { Properties of Database Config }
    property Database: string read getDatabase write setDatabase;
    property Host: string read getHost write setHost;
    property Username: string read getUsername write setUsername;
    property Password: string read getPassword write setPassword;
  end;

  { THadeBaseConnection }
  {* base class for all concreate Connection service
   * this class implement basic config for connection
   * to avoid code repeation. see implementation for details.
   * concreate Connection Service derrive from this class
   * and implemented other IHadeConnection method
   * for example see unit HadeSqldbConnection.pas }
  { class visibility : Private,don't use directly if you don't know what you do }
  THadeBaseConnection = class(THadeBaseObject)
  private
    FDatabase, FHost, FUsername, FPassword: string;
  protected
    function getDatabase: string;
    function getHost: string;
    function getPassword: string;
    function getUsername: string;
    procedure setDatabase(AValue: string);
    procedure setHost(AValue: string);
    procedure setPassword(AValue: string);
    procedure setUsername(AValue: string);
  public
    property Database: string read getDatabase write setDatabase;
    property Host: string read getHost write setHost;
    property Username: string read getUsername write setUsername;
    property Password: string read getPassword write setPassword;
  end;

implementation

{ THadeBaseConnection }

function THadeBaseConnection.getDatabase: string;
begin
  Result := FDatabase;
end;

function THadeBaseConnection.getHost: string;
begin
  Result := FHost;
end;

function THadeBaseConnection.getPassword: string;
begin
  Result := FPassword;
end;

function THadeBaseConnection.getUsername: string;
begin
  Result := FUsername;
end;

procedure THadeBaseConnection.setDatabase(AValue: string);
begin
  if FDatabase = AValue then
    exit;
  FDatabase := Trim(AValue);
end;

procedure THadeBaseConnection.setHost(AValue: string);
begin
  if FHost = AValue then
    exit;
  FHost := Trim(AValue);
end;

procedure THadeBaseConnection.setPassword(AValue: string);
begin
  if FPassword = AValue then
    exit;
  FPassword := Trim(AValue);
end;

procedure THadeBaseConnection.setUsername(AValue: string);
begin
  if FUsername = AValue then
    exit;
  FUsername := Trim(AValue);
end;

end.

